import 'package:aio/aio.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/http_data.dart';
import 'package:app/src/http/bean/user.dart';
import 'package:app/src/http/bean/worksdo/material_requisition_bean.dart';
import 'package:app/src/http/bean/wroks/contract_bean.dart';
import 'package:app/src/http/model/user_model.dart';
import 'package:app/src/manager/ywx_manager.dart';
import 'package:app/src/ui/dialog/dailog.dart';
import 'package:app/src/utils/status_utils.dart';

import '../../../ui/route/main/main.dart';
import '../../model/material_requisition_model.dart';
import '../worksdo/equipment_management_bean.dart';
import '../worksdo/hardware_return_bean.dart';
import '../ywx_limit.dart';
import 'dispatchingaudit_bean.dart';

///搜索条件
class SearchInfo extends ContractCopyInfo {
  YwxItem? item;

  SearchInfo(YwxItem? item) {
    this.item = item;
    if (item != null) {}
  }

  ///通用显示数据集合。
  List<SearchBean>? searchDatas = null;

  ///合同编号
  String? ContractCode = "";
  bool isShowContractCode = false;
  bool readOnlyWithContractCode = false;
  String? showContractCodeName = null; //默认显示合同编号；可以自定义显示名称，如 销售合同号

  ///合同外部编号
  String? OutCode = "";
  bool isShowOutCode = false;
  String? ShowOutCodeName = null;

  ///批次号
  String? PoCode = "";
  bool isShowPoCode = false;

  ///订单编号
  String? OrderCode = "";
  bool isShowOrderCode = false;

  ///订单外部编号
  String? OrderOutCode = "";
  bool isShowOrderOutCode = false;

  ///通知单号
  String? NoticeId = "";
  bool isShowNoticeId = false;

  ///申请单号
  String? ApplicationCode = "";
  bool isShowApplicationCode = false;

  //领料单号
  String? PickCode = "";
  bool isShowPickCode = false;

  ///申请人
  UserApplicant? UserPerson = null;
  String? showUserPerson = null;
  bool isEnableInputUserPerson = true; //是否允许手动输入人名。
  bool isShowUserPerson = false;

  ///项目名称
  String? ProjectName = "";
  bool isShowProjectName = false;

  ///客户名称
  String? CustomerName = "";
  bool isShowCustomerName = false;

  ///规格
  String? Size = "";
  bool isShowSize = false;

  ///客服经理
  String? MerchandiserName = "";
  bool isShowMerchandiserName = false;

  ///客服经理
  List<UserInfo>? _Merchandisers = null;

  ///销售经理
  String? SalesmanName = "";
  bool isShowSalesmanName = false;

  ///销售经理
  List<UserInfo>? _Salesmans = null;

  ///所属工序
  String? ProcessName = "";
  String? ProcessId = "";
  bool isShowProcessName = false;
  List<OtherWorkApply>? _Process = null;

  ///申请班组
  String? ApplicationClassName = ""; //申请班组
  String? ApplicationClassId = ""; //申请班组id
  bool isShowApplicationClassName = false;

  ///申请班组
  List<OtherWorkApply>? ApplicationClass = null;

  //姓名
  String? TheName = "";
  bool isShowTheName = false;

  //加班时长（分钟）,开始时间
  String? OvertimeHoursStart = "";

  //加班时长（分钟）,结束时间
  String? OvertimeHoursEnd = "";
  bool isShowOvertimeHours = false;

  ///判断开始时长不能大于结束时长。
  bool isOvertimeHours() {
    if (isShowOvertimeHours) {
      if (StringUtils.isNotEmpty(OvertimeHoursStart) &&
          StringUtils.isNotEmpty(OvertimeHoursEnd)) {
        try {
          var start = double.parse(OvertimeHoursStart!);
          var end = double.parse(OvertimeHoursEnd!);
          if (start > end) {
            return false; //fixme 开始时长不能大于结束时长。
          }
        } catch (e) {}
      }
    }
    return true;
  }

  ///审核状态，默认全都有。
  ///默认审核中
  String? OrderType = AppStatusUtils.status_1;
  String? Status = AppStatusUtils.status_1;
  String? IsApproval = "false";

  bool isApproval() {
    if (IsApproval == "false") {
      return false;
    }
    return true;
  }

  bool isShowStatus = true;
  bool isShowStatusAll = true; //审核状态是否具备全显示；

  ///获取审核状态
  String getStatusOrderType(BuildContext context) {
    if (StringUtils.isEmpty(Status)) {
      if (_isDel) {
        return "";
      }
      //全显示
      return AppStrings.of(context).Status0;
    } else if (AppStatusUtils.status_1 == Status) {
      //审核中
      return AppStrings.of(context).Status1;
    } else if (AppStatusUtils.status_2 == Status) {
      //已审核
      return AppStrings.of(context).Status2;
    }
    return AppStrings.of(context).Status0;
  }

  bool _isDel = false; //是否操作了删除。
  ///设置审核状态；
  ///StatusUtils.status_1 审核中
  ///StatusUtils.status_2 已审核
  ///null 全显示
  void setStatusOrderType(String? Status, {bool isDel = false}) {
    _isDel = isDel;
    this.OrderType = Status;
    this.Status = Status;
    if (StringUtils.isEmpty(Status)) {
      //全显示
      IsApproval = null;
    } else if (AppStatusUtils.status_1 == Status) {
      //审核中
      IsApproval = "false";
    } else if (AppStatusUtils.status_2 == Status) {
      //已审核
      IsApproval = "true";
    }
  }

  ///开始提交时间(时间在SubData里，不在ContractCopyInfo)
  String? InsertStartDatetime = "";

  DateTime? getInsertStartDatetimeWithDateTime() {
    if (StringUtils.isEmpty(InsertStartDatetime)) {
      return null;
    }
    //默认格式是 yyyy-MM-dd 是不可省略的。后面的时分秒是可选位置参数。
    return DateTime.parse(InsertStartDatetime!);
  }

  ///结束提交时间
  String? InsertEndDatetime = "";

  DateTime? getInsertEndDatetimeWithDateTime() {
    if (StringUtils.isEmpty(InsertEndDatetime)) {
      return null;
    }
    //默认格式是 yyyy-MM-dd 是不可省略的。后面的时分秒是可选位置参数。
    return DateTime.parse(InsertEndDatetime!);
  }

  ///时间搜索条件，默认全部都有。
  bool isShowAddTime = true;

  //申请日期名称
  String? showAddTime = null;

  String getAddTime() {
    if (StringUtils.isEmpty(InsertStartDatetime)) {
      return "";
    }
    if (StringUtils.isEmpty(InsertEndDatetime)) {
      return "";
    }
    return InsertStartDatetime! + "~" + InsertEndDatetime!;
  }

  ///fixme 采购申请日期
  String? BPurStartDate = "";

  DateTime? getBPurStartDate() {
    if (StringUtils.isEmpty(BPurStartDate)) {
      return null;
    }
    //默认格式是 yyyy-MM-dd 是不可省略的。后面的时分秒是可选位置参数。
    return DateTime.parse(BPurStartDate!);
  }

  ///采购申请日期 结束日期
  String? EPurStartDate = "";

  DateTime? getEPurStartDate() {
    if (StringUtils.isEmpty(EPurStartDate)) {
      return null;
    }
    //默认格式是 yyyy-MM-dd 是不可省略的。后面的时分秒是可选位置参数。
    return DateTime.parse(EPurStartDate!);
  }

  ///是否显示采购申请日期
  bool isShowPurStartDate = false;

  String getPurStartDate() {
    if (StringUtils.isEmpty(BPurStartDate)) {
      return "";
    }
    if (StringUtils.isEmpty(EPurStartDate)) {
      return "";
    }
    return BPurStartDate! + "~" + EPurStartDate!;
  }

  ///fixme 采购要货日期
  String? BPurEndDate = "";

  DateTime? getBPurEndDate() {
    if (StringUtils.isEmpty(BPurEndDate)) {
      return null;
    }
    //默认格式是 yyyy-MM-dd 是不可省略的。后面的时分秒是可选位置参数。
    return DateTime.parse(BPurEndDate!);
  }

  ///采购要货日期 结束日期
  String? EPurEndDate = "";

  DateTime? getEPurEndDate() {
    if (StringUtils.isEmpty(EPurEndDate)) {
      return null;
    }
    //默认格式是 yyyy-MM-dd 是不可省略的。后面的时分秒是可选位置参数。
    return DateTime.parse(EPurEndDate!);
  }

  ///是否显示采购要货日期
  bool isShowPurEndDate = false;

  String getPurEndDate() {
    if (StringUtils.isEmpty(BPurEndDate)) {
      return "";
    }
    if (StringUtils.isEmpty(EPurEndDate)) {
      return "";
    }
    return BPurEndDate! + "~" + EPurEndDate!;
  }

  ///fixme 签订日期
  String? SignSDateTime = ""; //签订开始时间

  DateTime? getSignSDateTime() {
    if (StringUtils.isEmpty(SignSDateTime)) {
      return null;
    }
    //默认格式是 yyyy-MM-dd 是不可省略的。后面的时分秒是可选位置参数。
    return DateTime.parse(SignSDateTime!);
  }

  ///签订结束时间
  String? SignEDateTime = "";

  DateTime? getSignEDateTime() {
    if (StringUtils.isEmpty(SignEDateTime)) {
      return null;
    }
    //默认格式是 yyyy-MM-dd 是不可省略的。后面的时分秒是可选位置参数。
    return DateTime.parse(SignEDateTime!);
  }

  ///是否显示签订日期
  bool isShowSignSDateTime = false;

  String getSignDateTime() {
    if (StringUtils.isEmpty(SignSDateTime)) {
      return "";
    }
    if (StringUtils.isEmpty(SignEDateTime)) {
      return "";
    }
    return SignSDateTime! + "~" + SignEDateTime!;
  }

  ///物料请购
  String RequisitionStatus = "";

  ///是否显示物料请购，如：原片请购，已生成
  bool isShowRequisitionStatus = false;

  ///所属工厂
  Factory? factory = null;
  bool isShowFactory = false;
  bool isDelFactory = true; //工厂是否允许删除

  ///种类
  String SpeciesName = ""; //种类名称，如:原片种类，辅料种类，五金种类
  OtherWorkApply? Species = null;
  bool isShowSpecies = false;

  ///部门id
  String DeptId = "";
  String DeptName = "";
  bool isShowDept = false;

  ///品牌
  String BrandName = ""; //品牌名称，如:原片品牌，辅料品牌，五金品牌
  String? ManufacturerId = ""; //品牌id
  OtherWorkApply? Brand = null;
  bool isShowBrand = false;

  ///供应商
  String? SupplierId = ""; //供应商id
  String? SupplierName = ""; //供应商名称
  bool isShowSupplier = false;

  ///采购员
  String? Creater = ""; //采购员ID
  String? CreaterName = ""; //采购员名称
  bool isCreater = false;

  ///物料名称
  String? PreMaterialName = null; //显示名称
  String? MaterialName = "";
  bool isShowMaterialName = false;

  ///物料类型 ；MT01：原片 MT02：辅料 MT03：五金
  String? MaterialType = ""; //物料类型
  OtherWorkApply? TypeOfMaterial = null;
  bool isShowTypeOfMaterial = false;
  bool isShowTypeOfMaterialWithHasLimit = false; //是否根据权限去获取物料类型；
  List<OtherWorkApply>? ListTypeOfMaterial = null;

  List<OtherWorkApply> getListTypeOfMaterial(BuildContext context) {
    if (ListTypeOfMaterial == null) {
      //原片
      OtherWorkApply m = OtherWorkApply();
      m.key = PurDemand.MT01; //"MT01";
      m.value = AppStrings.of(context).Raw;
      m.Id = m.key;
      m.Name = m.value;
      //辅料
      OtherWorkApply m2 = OtherWorkApply();
      m2.key = PurDemand.MT02; //"MT02";
      m2.value = AppStrings.of(context).SupplementaryMaterial;
      m2.Id = m2.key;
      m2.Name = m2.value;
      //五金
      OtherWorkApply m3 = OtherWorkApply();
      m3.key = PurDemand.MT03; //"MT03";
      m3.value = AppStrings.of(context).Hardware;
      m3.Id = m3.key;
      m3.Name = m3.value;
      if (isShowTypeOfMaterialWithHasLimit) {
        ///fixme 根据权限动态加载物料类型条件
        ListTypeOfMaterial = [];
        s_YwxDatas?.forEach((element) {
          if (element.isHasLimit()) {
            if (element.YwxId == "N8002-3" || element.YwxId == "N8002-3") {
              if (!ListTypeOfMaterial!.contains(m)) {
                ListTypeOfMaterial?.add(m); //原片
              }
            } else if (element.YwxId == "N8013-3" ||
                element.YwxId == "N8013-3") {
              if (!ListTypeOfMaterial!.contains(m2)) {
                ListTypeOfMaterial?.add(m2); //辅料
              }
            } else if (element.YwxId == "N8014-3" ||
                element.YwxId == "N8014-3") {
              if (!ListTypeOfMaterial!.contains(m3)) {
                ListTypeOfMaterial?.add(m3); //五金
              }
            }
          }
        });
      } else {
        ListTypeOfMaterial = [m, m2, m3];
      }
    }
    return ListTypeOfMaterial!;
  }

  ///请购单号
  String? PurchaseOrderNumber = "";
  bool isShowPurchaseOrderNumber = false;

  ///采购单号
  String? PurOrderCode = "";
  bool isPurOrderCode = false;

  ///采购合同号
  String? PurContractCode = "";
  bool isPurContractCode = false;

  ///采购合同审核里的 子合同号
  String? PurBodyCode = "";
  bool isPurBodyCode = false;

  ///运输合同号
  String? LContractCode = "";
  bool isLContractCode = false;

  ///承运商
  String? CarrierId = "";
  String? CarrierName = "";
  bool isCarrier = false;

  ///创建人
  String? FounderId = null;
  String? FounderName = null;
  bool isShowFounder = false;
  bool isLContract = false; //是否为运输合同里的创建人

  ///状态(主要是物料请求单的状态)
  String? DocumentStatus = ""; //请购单审核，单据状态；
  OtherWorkApply? PurchaseStatus = null;
  bool isShowPurchaseStatus = false;
  String? showPurchaseStatusName = null;
  List<OtherWorkApply>? ListPurchaseStatus = null;

  List<OtherWorkApply> getListPurchaseStatus(BuildContext context) {
    if (ListPurchaseStatus == null) {
      // <option value="0">已录入</option>
      // <option value="1">审核中</option>
      // <option value="2">已审核</option>
      // <option value="3">已生成采购单</option>
      // <option value="4">已生成采购合同</option>
      // <option value="5">提货中</option>
      // <option value="6">已入库</option>
      // <option value="1000">已关闭</option>
      //已录入
      OtherWorkApply m = OtherWorkApply();
      m.key = "0";
      m.value = AppStrings.of(context).EnteredIn;
      m.Id = m.key;
      m.Name = m.value;
      //审核中
      OtherWorkApply m2 = OtherWorkApply();
      m2.key = "1";
      m2.value = AppStrings.of(context).Inthereview;
      m2.Id = m2.key;
      m2.Name = m2.value;
      //已审核
      OtherWorkApply m3 = OtherWorkApply();
      m3.key = "2";
      m3.value = AppStrings.of(context).Theapproved;
      m3.Id = m3.key;
      m3.Name = m3.value;
      //已生成采购单
      OtherWorkApply m4 = OtherWorkApply();
      m4.key = "3";
      m4.value = AppStrings.of(context).PurchaseStatus4;
      m4.Id = m4.key;
      m4.Name = m4.value;
      ListPurchaseStatus = [m, m2, m3, m4];
      //已生成采购合同
      OtherWorkApply m5 = OtherWorkApply();
      m5.key = "4";
      m5.value = AppStrings.of(context).PurchaseStatus5;
      m5.Id = m5.key;
      m5.Name = m5.value;
      //提货中
      OtherWorkApply m6 = OtherWorkApply();
      m6.key = "5";
      m6.value = AppStrings.of(context).PurchaseStatus6;
      m6.Id = m6.key;
      m6.Name = m6.value;
      //已入库
      OtherWorkApply m7 = OtherWorkApply();
      m7.key = "6";
      m7.value = AppStrings.of(context).PurchaseStatus7;
      m7.Id = m7.key;
      m7.Name = m7.value;
      //已关闭
      OtherWorkApply m8 = OtherWorkApply();
      m8.key = "1000";
      m8.value = AppStrings.of(context).PurchaseStatus8;
      m8.Id = m8.key;
      m8.Name = m8.value;
      ListPurchaseStatus = [m, m2, m3, m4, m5, m6, m7, m8];
    }
    return ListPurchaseStatus!;
  }

  ///五金领用记录，领用单状态(我的工单：五金领用记录)
  String? ReceivingStatusKey = "";
  String? ReceivingStatusValue = "";
  bool isShowReceivingStatus = false;
  var ReceivingStatusDatas = <RollerBean>[]; //状态数据
  List<RollerBean> getReceivingStatusDatas(BuildContext context) {
    if (ReceivingStatusDatas.length <= 0) {
      //状态：未领用，已领用，退库中，已退回
      ReceivingStatusDatas = HardwareReturnListBean.getStatus(context);
    }
    return ReceivingStatusDatas;
  }

  //我的工单：设备编码
  String? DeviceCoding = "";
  bool isShowDeviceCoding = false;

  //搜索条件，不显示设备编码；但是二维码扫描出来的编码，可以显示在搜索条件查询界面。
  bool isShowDeviceCodingWithUi = false;
  bool isScanDeviceCodingResult = false; //fixme 判断该编码是否为二维码扫描出来的结果。

  //设备管理信息
  EquipmentInfo? equipmentInfo;

  ///条件清空
  void clear() {
    if (!readOnlyWithContractCode) {
      //readOnlyWithContractCode为true只读的时候不能清除。
      //合同编号
      ContractCode = null;
    }
    searchDatas?.forEach((element) {
      element.clear();
    });
    //合同外部编号
    OutCode = "";
    //批次号
    PoCode = null;
    //订单编号
    OrderCode = null;
    //订单外部编号
    OrderOutCode = null;
    //通知单号
    NoticeId = null;
    //fixme 申请单号
    ApplicationCode = null;
    Applicationcode = null;
    //领料单号
    PickCode = null;
    //fixme 项目名称
    ProjectName = null;
    Projectname = null;
    //fixme 客户名称
    CustomerName = null;
    Customername = null;
    //fixme 客服经理
    MerchandiserName = null;
    Merchandisername = null;
    //fixme 销售经理
    SalesmanName = null;
    Salesmanname = null;
    //所属工序
    ProcessName = null;
    ProcessId = null;
    //申请班组
    ApplicationClassName = null;
    ApplicationClassId = null;
    //姓名
    TheName = null;
    //加班时长
    OvertimeHoursStart = null;
    OvertimeHoursEnd = null;
    if (isShowStatusAll) {
      //审核状态,全显示下，才有清除操作。
      setStatusOrderType(null, isDel: true);
    }
    //添加时间
    InsertStartDatetime = "";
    InsertEndDatetime = "";
    //RequisitionStatus //fixme 物料请购不允许清除的，必须有一个状态。
    //print("是否清空工厂：$isDelFactory");
    //所属工厂
    if (isDelFactory) {
      factory = null;
    }
    //种类
    Species = null;
    //品牌
    Brand = null;
    ManufacturerId = "";
    //物料名称
    MaterialName = "";
    //物料类型
    TypeOfMaterial = null;
    //请购单号
    PurchaseOrderNumber = "";
    //创建人
    FounderId = null;
    FounderName = null;
    //状态（采购状态）
    PurchaseStatus = null;
    DocumentStatus = "";
    //申请人
    UserPerson = null;
    //规格
    Size = "";
    //采购申请日期
    BPurStartDate = "";
    EPurStartDate = "";
    //采购要货日期
    BPurEndDate = "";
    EPurEndDate = "";
    //供应商
    SupplierId = "";
    SupplierName = "";
    if (isShowTypeOfMaterial) {
      //fixme 物料类型
      MaterialType = "";
    }
    //部门
    DeptId = "";
    DeptName = "";
    //采购单号
    PurOrderCode = "";
    //采购合同号
    PurContractCode = "";
    //子合同编号
    PurBodyCode = "";
    //采购员
    Creater = "";
    CreaterName = "";
    //签订日期
    SignSDateTime = "";
    SignEDateTime = "";
    //运输合同号
    LContractCode = "";
    //承运商
    CarrierId = "";
    CarrierName = "";
    //我的工单：五金领用单状态
    ReceivingStatusKey = "";
    ReceivingStatusValue = "";
    //我的工单设备编码
    DeviceCoding = "";
  }

  ///工种“02”  销售经理
  void getManagergetlistWith02(BuildContext context,
      ResponseCallbackWithT<List<UserInfo>> responseCallbackWithT) {
    if (_Salesmans != null && _Salesmans!.length > 0) {
      responseCallbackWithT.call(_Salesmans!);
      return;
    }
    UserModel.getManagergetlistWith02(context, true, (value) {
      if (value.isSuccessForCode()) {
        _Salesmans = value.Data;
        responseCallbackWithT.call(_Salesmans!);
      } else {
        AppDialog.showDialogWithInfo(context, content: value?.MsgDetail);
      }
    });
  }

  ///“03”  客服经理
  void getManagergetlistWith03(BuildContext context,
      ResponseCallbackWithT<List<UserInfo>> responseCallbackWithT) {
    if (_Merchandisers != null && _Merchandisers!.length > 0) {
      responseCallbackWithT.call(_Merchandisers!);
      return;
    }
    UserModel.getManagergetlist(context, "03", true, (value) {
      if (value.isSuccessForCode()) {
        _Merchandisers = value.Data;
        responseCallbackWithT.call(_Merchandisers!);
      } else {
        AppDialog.showDialogWithInfo(context, content: value?.MsgDetail);
      }
    });
  }

  ///获取所属工序
  void getOtherWorkApply(BuildContext context,
      ResponseCallbackWithT<List<OtherWorkApply>> responseCallbackWithT) {
    if (_Process != null && _Process!.length > 0) {
      responseCallbackWithT.call(_Process!);
      return;
    }
    ProcessQuery processQuery = ProcessQuery();
    processQuery.type = "Process";
    UserModel.getOtherWorkApply(context, processQuery, true, (value) {
      if (value.isSuccessForCode()) {
        _Process = value.Data;
        responseCallbackWithT.call(_Process!);
      } else {
        AppDialog.showDialogWithInfo(context, content: value?.MsgDetail);
      }
    });
  }

  ///获取所属班组
  void getOtherWorkApplyWitHClass(BuildContext context,
      ResponseCallbackWithT<List<OtherWorkApply>> responseCallbackWithT) {
    if (ApplicationClass != null && ApplicationClass!.length > 0) {
      responseCallbackWithT.call(ApplicationClass!);
      return;
    }
    ProcessQuery processQuery = ProcessQuery();
    processQuery.type = "Group";
    processQuery.processId = ProcessId;
    UserModel.getOtherWorkApply(context, processQuery, true, (value) {
      if (value.isSuccessForCode()) {
        ApplicationClass = value.Data;
        responseCallbackWithT.call(ApplicationClass!);
      } else {
        AppDialog.showDialogWithInfo(context, content: value?.MsgDetail);
      }
    });
  }

  ///获取物料种类
  void getOtherWorkApply2(BuildContext context, PreSearchMaterialInfo data,
      ResponseCallbackWithT<List<OtherWorkApply>> responseCallbackWithT) {
    MaterialModel.getOtherWorkApply2(context, data, true, (value) {
      if (value.isSuccessForCode()) {
        responseCallbackWithT.call(value.Data!);
      } else {
        AppDialog.showDialogWithInfo(context, content: value?.MsgDetail);
      }
    });
  }

  ///获取部门
  void getdepartment(BuildContext context,
      ResponseCallbackWithT<List<Department>> responseCallbackWithT) {
    UserModel.getDepartments(context, true, (value) {
      //print("=========================================是否成功${value.isSuccessForCode()}");
      if (value.isSuccessForCode()) {
        responseCallbackWithT.call(value.Data!);
      } else {
        //print("错误提示信息：${value?.MsgDetail}");
        AppDialog.showDialogWithInfo(context, content: value?.MsgDetail);
      }
    });
  }

  // ContractCopyInfo _contractCopyInfo = ContractCopyInfo();
  //
  // ///获取搜索条件;fixme 现在搜索类已经继承ContractCopyInfo，所以不需要再转为ContractCopyInfo类了。
  // ContractCopyInfo getContractCopyInfo() {
  //   _contractCopyInfo
  //     ..PoCode = PoCode //PoCode批次号
  //     ..OrderCode = OrderCode //订单编号
  //     ..OrderOutCode = OrderOutCode //订单编号（外部）
  //     ..ContractCode = ContractCode //合同编号
  //     ..OutCode = OutCode //合同外部编号
  //     ..NoticeId = NoticeId //通知单号
  //     ..ApplicationCode = ApplicationCode //申请类型
  //     ..ProjectName = ProjectName //项目名称
  //     ..CustomerName = CustomerName //客户名称
  //     ..SalesmanName = SalesmanName //业务员姓名(销售经理)
  //     ..MerchandiserName = MerchandiserName //跟单员姓名(客服经理)
  //     ..OrderType = OrderType //订单状态0：普通，1：审核中，2：已审核
  //     ..Status = Status //单据状态，审核状态
  //     ..IsApproval = IsApproval; //判断是否已审核
  //   return _contractCopyInfo;
  // }

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    super.fromJson(json); //fixme 先调用父类的。
    PoCode = json["PoCode"]?.toString() ?? "";
    OrderCode = json["OrderCode"]?.toString() ?? "";
    OrderOutCode = json["OrderOutCode"]?.toString() ?? "";
    ContractCode = json["ContractCode"]?.toString() ?? "";
    OutCode = json["OutCode"]?.toString() ?? "";
    NoticeId = json["NoticeId"]?.toString() ?? "";
    ApplicationCode = json["ApplicationCode"]?.toString() ?? "";
    ProjectName = json["ProjectName"]?.toString() ?? "";
    CustomerName = json["CustomerName"]?.toString() ?? "";
    SalesmanName = json["SalesmanName"]?.toString() ?? "";
    MerchandiserName = json["MerchandiserName"]?.toString() ?? "";
    OrderType = json["OrderType"]?.toString() ?? "";
    Status = json["Status"]?.toString() ?? "";
    IsApproval = json["IsApproval"]?.toString() ?? "";
    InsertStartDatetime = json["InsertStartDatetime"]?.toString() ?? "";
    InsertEndDatetime = json["InsertEndDatetime"]?.toString() ?? "";
    ProcessName = json["ProcessName"]?.toString() ?? "";
    ProcessId = json["ProcessId"]?.toString() ?? "";
    ApplicationClassId = json["ApplicationClassId"]?.toString() ?? "";
    ApplicationClassName = json["ApplicationClassName"]?.toString() ?? "";
    TheName = json["TheName"]?.toString() ?? "";
    OvertimeHoursStart = json["OvertimeHoursStart"]?.toString() ?? "";
    OvertimeHoursEnd = json["OvertimeHoursEnd"]?.toString() ?? "";
    RequisitionStatus = json["RequisitionStatus"]?.toString() ?? "";
    factory = setGenericFromJson(json, 'factory', Factory(), "");
    Species = setGenericFromJson(json, 'Species', OtherWorkApply(), "");
    Brand = setGenericFromJson(json, 'Brand', OtherWorkApply(), "");
    MaterialName = json["MaterialName"]?.toString() ?? "";
    PickCode = json["PickCode"]?.toString() ?? "";
    UserPerson = setGenericFromJson(json, 'UserPerson', UserApplicant(), "");
    Size = json["Size"]?.toString() ?? "";
    ReceivingStatusKey = json["ReceivingStatusKey"]?.toString() ?? "";
    ReceivingStatusValue = json["ReceivingStatusValue"]?.toString() ?? "";
    DeviceCoding = json["DeviceCoding"]?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return SearchInfo(null);
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    // var map = <String, dynamic>{};
    var map = super.toJson(); //fixme 先调用父类的。
    map["PoCode"] = PoCode;
    map["OrderCode"] = OrderCode;
    map["OrderOutCode"] = OrderOutCode;
    //print("合同编号：$ContractCode\t${super.ContractCode}");
    map["ContractCode"] = ContractCode;
    map["OutCode"] = OutCode;
    map["NoticeId"] = NoticeId;
    map["ApplicationCode"] = ApplicationCode;
    map["ProjectName"] = ProjectName;
    map["CustomerName"] = CustomerName;
    map["SalesmanName"] = SalesmanName;
    map["MerchandiserName"] = MerchandiserName;
    map["OrderType"] = OrderType;
    map["Status"] = Status;
    map["IsApproval"] = IsApproval;
    map["InsertStartDatetime"] = InsertStartDatetime;
    map["InsertEndDatetime"] = InsertEndDatetime;
    map["ProcessName"] = ProcessName;
    map["ProcessId"] = ProcessId;
    map["ApplicationClassId"] = ApplicationClassId;
    map["ApplicationClassName"] = ApplicationClassName;
    map["TheName"] = TheName;
    map["OvertimeHoursStart"] = OvertimeHoursStart;
    map["OvertimeHoursEnd"] = OvertimeHoursEnd;
    map["RequisitionStatus"] = RequisitionStatus;
    map["factory"] = factory;
    map["Species"] = Species;
    map["Brand"] = Brand;
    map["ManufacturerId"] = ManufacturerId;
    map["MaterialName"] = MaterialName;
    map["PickCode"] = PickCode;
    map["UserPerson"] = UserPerson;
    map["Size"] = Size;
    map["EPurStartDate"] = EPurStartDate;
    map["BPurStartDate"] = BPurStartDate;
    map["BPurEndDate"] = BPurEndDate;
    map["EPurEndDate"] = EPurEndDate;
    map["DocumentStatus"] = DocumentStatus;
    map["SupplierId"] = SupplierId;
    map["SupplierName"] = SupplierName;
    map["PurchaseOrderNumber"] = PurchaseOrderNumber;
    map["MaterialType"] = MaterialType;
    map["TypeOfMaterial"] =
        MaterialType; //fixme 物料类型，MaterialType 和 TypeOfMaterial 共用MaterialType
    map["FounderName"] = FounderName;
    map["FounderId"] = FounderId;
    map["DeptId"] = DeptId;
    map["DeptName"] = DeptName;
    map["PurOrderCode"] = PurOrderCode;
    map["PurContractCode"] = PurContractCode;
    map["PurBodyCode"] = PurBodyCode;
    map["Creater"] = Creater;
    map["CreaterName"] = CreaterName;
    map["SignSDateTime"] = SignSDateTime;
    map["SignEDateTime"] = SignEDateTime;
    map["InsertStartDatetime"] = InsertStartDatetime ?? "";
    map["InsertEndDatetime"] = InsertEndDatetime ?? "";
    map["LContractCode"] = LContractCode ?? "";
    map["CarrierId"] = CarrierId ?? "";
    map["CarrierName"] = CarrierName ?? "";
    map["ReceivingStatusKey"] = ReceivingStatusKey ?? "";
    map["ReceivingStatusValue"] = ReceivingStatusValue ?? "";
    map["DeviceCoding"] = DeviceCoding ?? "";
    return map;
  }
}

///搜索实体类
class SearchBean extends BaseBean {
  String? id = "";
  bool isShow = true; //是否显示，默认显示。
  String? showName = ""; //显示名称
  String? showValue = ""; //显示内容

  List<RollerBean>? datas = null; //数据集合
  RollerBean? data = null; //当前选中数据

  bool isTime = false; //是否为时间类型。
  //时间格式：yyyy-MM-dd HH:mm:ss
  String? StartDate = ""; //开始日期
  String? EndDate = ""; //接收日期

  ///数据清空
  clear() {
    showValue = "";
    data = null;
    StartDate = "";
    EndDate = "";
  }

  @override
  fromJson(Map<String, dynamic> json) {
    //print("进来了：\t$json");
    isShow = json["isShow"] ?? true;
    showName = json["showName"]?.toString() ?? "";
    showValue = json["showValue"]?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return SearchBean();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["isShow"] = isShow;
    map["showName"] = showName;
    map["showValue"] = showValue;
    map["StartDate"] = StartDate;
    map["EndDate"] = EndDate;
    return map;
  }
}
